package com.gark.pieceswallpaper;

import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.service.wallpaper.WallpaperService;

/**
 * Created by Gark on 25.05.13.
 */
public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.prefs);

        Preference morePref = (Preference) findPreference(getString(R.string.more_key));
        Preference ratePref = (Preference) findPreference(getString(R.string.rate_key));
        morePref.setOnPreferenceClickListener(this);
        ratePref.setOnPreferenceClickListener(this);

    }

    @Override
    public boolean onPreferenceClick(Preference preference) {
        Intent intent = null;

        if (preference.getKey().equals(getString(R.string.more_key))) {
            final String appName = "Modest Fish";
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://developer?id=" + appName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/developer?id=" + appName)));
            }
        } else if (preference.getKey().equals(getString(R.string.rate_key))) {
            final String appName = "com.gark.pieceswallpaper";
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appName)));
            }

        }

        return false;
    }


//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//
//        Intent i = new Intent(this, MyWallpaperService.class);
//        if (Build.VERSION.SDK_INT > 15) {
//            i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
//            String pkg = WallpaperService.class.getPackage().getName();
//            String cls = WallpaperService.class.getCanonicalName();
//            i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(pkg, cls));
//        } else {
//            i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
//        }
//        startService(i);
//    }


}